﻿using Microsoft.AspNetCore.Mvc;
using Travel.Data.Dtos.TravelBusiness;
using Travel.Data.Dtos;
using Travel.Data.Inputs;
using Travel.Data;
using Travel.Service.TravelBusiness;
using Microsoft.AspNetCore.Authorization;
using Travel.API.Filters;
using Travel.Data.Consts;

namespace Travel.API.Controller
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class TravelController : BaseController
    {
        private readonly ITraveIService _traveIService;
        //private readonly IExcelExportManager _excelExportManager; 

        public TravelController(ITraveIService traveIService)
        {
            _traveIService = traveIService;
        }
        /// <summary>
        /// 用户端-旅游景点查询
        /// </summary>
        /// <param name="travelQueryInput"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Results<PageDto<TravelDto>>> UserTravelQuery([FromBody] TravelQueryInput travelQueryInput)
        {
            travelQueryInput.IsUserSearch = true;
            return await _traveIService.TravelQuery(travelQueryInput);
        }
        /// <summary>
        /// 商家端-旅游景点查询
        /// </summary>
        /// <param name="travelQueryInput"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.SellerAdministrator)]
        public async Task<Results<PageDto<TravelDto>>> SellerTravelQuery([FromBody] TravelQueryInput travelQueryInput)
        {
            travelQueryInput.CreatedUserId = LoginUserId;
            return await _traveIService.TravelQuery(travelQueryInput);
        }
        /// <summary>
        /// 管理员-旅游景点查询
        /// </summary>
        /// <param name="travelQueryInput"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<PageDto<TravelDto>>> AdminTravelQuery([FromBody] TravelQueryInput travelQueryInput)
        {
            return await _traveIService.TravelQuery(travelQueryInput);
        }
        /// <summary>
        /// 查看详情
        /// </summary>
        /// <param name="travelId"></param>
        /// <returns></returns>
        [HttpGet("{travelId}")]
        [AllowAnonymous]
        public async Task<Results<TravelDetailDto>> GetDetail(long travelId)
        {
            return await _traveIService.GetDetail(travelId);
        }
        /// <summary>
        /// 旅游景点添加或者修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.SellerAdministrator)]
        public async Task<Results<int>> TravelAddOrUpdate([FromBody] TravelAddOrUpdateInput input)
        {
            return await _traveIService.TravelAddOrUpdate(input);
        }
        /// <summary>
        /// 删除旅游景点
        /// </summary>
        [TravelAuthorize(AuthorizeRoleName.SellerAdministrator)]
        [HttpDelete]
        public async Task<Results<int>> TracelDelete([FromBody] List<long> idList)
        {
            return await _traveIService.TracelDelete(CurrentRoleId, idList.ToArray());
        }

        /// <summary>
        /// 旅游景点审批
        /// </summary>
        /// <param name="travelAuditInput"></param>
        /// <returns></returns>
        /// <remarks>管理员才能审批</remarks>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<int>> TravelAudit([FromBody] TravelAuditInput input)
        {
            return await _traveIService.TravelAudit(input);
        }

        /// <summary>
        /// 上架或者下架旅游景点
        /// </summary>
        /// <param name="travelShekverOrUnShelveInput"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.AdminOrSeller)]
        public async Task<Results<int>> TravelShekverOrUnShelve([FromBody] TravelShekverOrUnShelveInput input)
        {
            return await _traveIService.TravelShekverOrUnShelve(input);
        }

        /// <summary>
        /// 设置领队
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.SellerAdministrator)]
        public async Task<Results<int>> SetTravelLeader(SetTravelLeaderInput input)
        {

            return await _traveIService.SetTravelLeader(input);
        }

        /// <summary>
        /// 查看游客列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.SellerAdministrator)]
        public async Task<Results<QueryTravelUserDto>> QueryTravelUserList([FromBody] TravelUserQueryInput input)
        {

            return await _traveIService.QueryTravelUserList(input);
        }
        // /// <summary>
        // /// 商家端-导出游客信息
        // /// </summary>
        // /// <param name="bo"></param>
        // /// <remarks>景点列表--->点击查看游客列表---->导出游客信息</remarks>
        // /// <returns></returns>
        // [HttpPost]
        // [TravelAuthorize(AuthorizeRoleName.SellerAdministrator)]
        // public IActionResult Export([FromBody]TravelUserQueryInput bo)
        // {
        //     var dto = _travelService.QueryTravelUserList(bo);
        //     return File(_excelExportManager.Export(dto.Data), "application/octet-stream", $"游客信息{DateTime.Now:yyyyMMdd}.xlsx");
        // }
    }
}
